<script setup>

import {ref} from "vue";
import dayjs from "dayjs";
import {baseUrl, reqInstance} from "@/utils/request/index.js";
import {message} from "ant-design-vue";

const visible = ref(false)

const emit = defineEmits(['create-completed'])

const defaultFormData = {
  id: 0,
  type_title: "",
  support_fixed_amount: true,
  support_divide_amount: true,
}

const formData = ref(defaultFormData)


const openDraw = (isEdit) => {
  visible.value = true
  if (!isEdit) {
    formData.value = defaultFormData
  }
  console.log(formData.value);
}

const updateOpen = (data) => {
  formData.value =  data
  openDraw(true)
}

const doSave = async ()=>{
  let url = "pro-type-fee"
  let method = "post"
  if (formData.value.id > 0 ) {
    url += "/" + formData.value.id
    method = "put"
  }
  try {
    await reqInstance({
      url: url,
      method: method,
      data: formData.value
    })
    message.success("保存成功")
    emit('create-completed')
    visible.value = false
  } catch (e) {

  }
}
defineExpose({openDraw,updateOpen})
</script>

<template>
  <a-drawer
      v-model:open="visible"
      class="custom-class"
      root-class-name="root-class-name"
      :root-style="{ color: 'blue' }"
      style="color: red"
      title="合同归档"
      placement="right"
  >
    <a-form layout="vertical" :model="formData">
      <a-form-item prop="com_name" label="类型名称">
        <a-input v-model:value="formData.type_title" placeholder="请输入类型名称"  style="width: calc(100% - 200px)"/>
      </a-form-item>
      <a-form-item label="固定金额">
        <a-radio-group v-model:value="formData.support_fixed_amount"  button-style="solid">
          <a-radio-button :value="false">否</a-radio-button>
          <a-radio-button :value="true">是</a-radio-button>
        </a-radio-group>
      </a-form-item>
      <a-form-item label="比例分成">
        <a-radio-group v-model:value="formData.support_divide_amount"  button-style="solid">
          <a-radio-button :value="false">否</a-radio-button>
          <a-radio-button :value="true">是</a-radio-button>
        </a-radio-group>
      </a-form-item>
      <a-form-item>
        <a-button type="primary" @click="doSave">保存</a-button>
      </a-form-item>
    </a-form>
  </a-drawer>
</template>

<style scoped>

</style>